package com.timothy.android.answer;

import com.timothy.android.BaseProcessActivity;
import com.timothy.android.R;
import com.timothy.android.view.SlideBean;
import com.timothy.service.MessageSenderUtil;
import com.timothy.statistics.AnswerBuilder;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;

public class SlideActivity extends BaseProcessActivity {
	private static final String LOG_TAG = "SlideAnswerActivity";
	
	private TableLayout tableLayout1;
	private TextView totalTV;
	private TextView averageTV;
	
	//header component(left, center,right)
	SlideBean slide = null;
	TextView answerDesc;
	Button nextBtn;

	//send answers to server
	public void sendNextQuestion(){
		Log.i(LOG_TAG, "sendNextQuestion()...");
		String message = MessageSenderUtil.sendNextQuestion();
		Log.i(LOG_TAG, "message:"+message);
		if(!sendMessage(message)){
			ShowDialog("Can not connect to pc, please confirm PC is running!");
		}
	}
	
	//set header
	public void setHeader(Integer type) {
		//set answerDesc
		answerDesc = (TextView) this.findViewById(R.id.answerDesc);
		answerDesc.setText("Slide:Q " + slide.getQuestionIndex().toString()+" of " + slide.getTotalQuestionCount().toString());
		
		//set next button
		if(slide.getQuestionIndex() == slide.getTotalQuestionCount()){
			ShowDialog("Vote Ended ! Please visit www.powercomars.com for more product information.");
		}else{
			if (MessageSenderUtil.MODE != null && MessageSenderUtil.MODE == 2) {
				nextBtn = (Button) this.findViewById(R.id.nextBtn);
				nextBtn.setVisibility(View.VISIBLE);
				nextBtn.setOnClickListener(new Button.OnClickListener() {
					public void onClick(View v) {
						sendNextQuestion();
					}
				});
			}
		}
	}
	

	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.answer_slide);

        Bundle bundle = this.getIntent().getExtras();
        String message = bundle.getString("message");
        
        slide = AnswerBuilder.parseSlideStatistics(message);
        setHeader(slide.getQuestionType());
 
//      //set tableLayout
        tableLayout1 = (TableLayout) this.findViewById(R.id.tableLayout1);
        tableLayout1.setBackgroundColor(Color.parseColor("#f57de7"));
        
//		//set total
//        totalDescTV = (TextView) this.findViewById(R.id.totalDescTV);
//        totalDescTV.setTextSize(30);
 
        totalTV = (TextView) this.findViewById(R.id.totalTV);
        totalTV.setTextSize(30);
        totalTV.setText(String.valueOf(slide.getTotal()));
        
//        //set average
//        averageDescTV = (TextView) this.findViewById(R.id.averageDescTV);
//        averageDescTV.setTextSize(30);

        averageTV = (TextView) this.findViewById(R.id.averageTV);
        averageTV.setTextSize(30);
        averageTV.setText(String.valueOf(slide.getAverage()));
        
    }
    
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}
    
    
    
}
